package metric

import (
	"gddgame.cc/galaxy/binocle"
	"github.com/toolkits/nux"
)

func Kernel(agent binocle.Service) error {
	if _, err := nux.KernelMaxFiles(); err != nil {
		return err
	}
	if _, err := nux.KernelMaxProc(); err != nil {
		return err
	}
	if _, err := nux.KernelAllocateFiles(); err != nil {
		return err
	}
	agent.AddMetrics().Collect(func() map[string]float32 {
		maxFiles, _ := nux.KernelMaxFiles()
		maxProc, _ := nux.KernelMaxProc()
		allocateFiles, _ := nux.KernelAllocateFiles()

		return map[string]float32{
			"kernel.maxfiles":        float32(maxFiles),
			"kernel.maxproc":         float32(maxProc),
			"kernel.files.allocated": float32(allocateFiles),
			"kernel.files.left":      float32(maxFiles - allocateFiles),
		}
	})
	return nil
}
